package com.summer.safe.system.service;

import com.summer.safe.base.BaseService;
import com.summer.safe.system.dao.DictDao;
import com.summer.safe.system.entity.Dict;
import com.summer.safe.utils.Global;
import com.summer.safe.utils.UserUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 字典Service
 *
 */
@Service
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class DictService extends BaseService<DictDao, Dict> {

    /**
     * 查询字段类型列表
     *
     * @return
     */
    public List<Dict> findTypeList() {
        return dao.findTypeList(new Dict());
    }

    @Override
    @Transactional(readOnly = false)
    public void save(Dict dict) {
        super.save(dict);

        //清除字典的缓存
        UserUtils.removeCache(Global.CACHE_DICT_MAP);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(Dict dict) {
        super.delete(dict);
    }

    public Dict getEntity(String parentId){

        return dao.getEntity(parentId);
    }



    /**
     * 根据类型批量的删除
     * @param type
     */
    @Transactional(readOnly = false)
    public void deleteType( String type){

         dao.deleteType(type);
    }




}
